package com.ease.core.skins {
	import com.ease.component.IconButton;
	
	import flash.display.GradientType;
	import flash.display.Graphics;
	
	import mx.skins.ProgrammaticSkin;
	import mx.styles.StyleManager;

	public class IconButtonSkin extends ProgrammaticSkin {

		override public function get measuredWidth():Number {
			return IconButton.BUTTON_WIDTH;
		}

		override public function get measuredHeight():Number {
			return IconButton.BUTTON_HEIGHT;
		}

		override protected function updateDisplayList(w:Number, h:Number):void {
			var borderColor:uint=getStyle("borderColor");
			var cornerRadius:Number=getStyle("cornerRadius");
			var fillAlphas:Array=getStyle("fillAlphas");
			var fillColors:Array=getStyle("fillColors");
			StyleManager.getStyleManager(null).getColorNames(fillColors);
			var highlightAlphas:Array=getStyle("highlightAlphas");
			var themeColor:uint=getStyle("themeColor");

			var backgroundColor:uint=getStyle("backgroundColor");
			var cr:Number=Math.max(0, cornerRadius);
			var cr1:Number=cr - 1; //Math.max(0, cornerRadius - 1);
			var g:Graphics=graphics;

			g.clear();
			switch (name) {
				case "selectedUpSkin":
				case "upSkin":
					break;
				case "selectedOverSkin":
				case "overSkin": 
					drawRoundRect(0, 0, w, h, cr, [borderColor, borderColor], 1, verticalGradientMatrix(0, 0, w, h), GradientType.LINEAR, null, {x: 1, y: 1, w: w - 2, h: h - 2, r: cr - 1});
					drawRoundRect(1, 1, w - 2, h - 2, cr1, fillColors, fillAlphas, verticalGradientMatrix(1, 1, w - 2, h - 2));
					drawRoundRect(1, 1, w - 2, (h - 2) / 2, {tl: cr1, tr: cr1, bl: 0, br: 0}, [0xFFFFFF, 0xFFFFFF], highlightAlphas, verticalGradientMatrix(1, 1, w - 2, (h - 2) / 2));
					break;
				case "downSkin":
				case "selectedDownSkin":
					drawRoundRect(0, 0, w, h, cr, [borderColor, borderColor], 1, verticalGradientMatrix(0, 0, w, h), GradientType.LINEAR, null, {x: 1, y: 1, w: w - 2, h: h - 2, r: cr - 1});
					drawRoundRect(1, 1, w - 2, h - 2, cr1, fillColors, fillAlphas, verticalGradientMatrix(1, 1, w - 2, h - 2));
					drawRoundRect(1, 1, w - 2, (h - 2) / 2, {tl: cr1, tr: cr1, bl: 0, br: 0}, [0xFFFFFF, 0xFFFFFF], highlightAlphas, verticalGradientMatrix(1, 1, w - 2, (h - 2) / 2));
			      break;
         }
		}
	}
}